<?php namespace App\Http\Controllers\user\uc\energy;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Http\Controllers\user\uc\CommonController;
use Illuminate\Http\Request;
use Input;
use App\Models\EnterpricePowerusersBase;
use App\Models\Users;
use Session;

class ValidatorController extends Controller {

	/**
	 * Display a listing of the resource.
	 *
	 * @return Response
	 */
	public function __construct()
	{
		$this->middleware('isattestation');
	}
	public function index()
	{
		$type = env('ENERGY');
		return view("user.uc.energy.add_groupinfo")->withSitePos("基本信息")->withParentPos($this->getRoleName($type))->withType($type)->withProvinces(CommonController::getAllProvince()->toArray());
	}

	public function addValidatorInfo()
	{
		$uid = $this->getUid();
		$model = EnterpricePowerusersBase::where("uid", $uid);
		if(!$model->count())
		{
			$data = Input::all();
			$imgArr = Input::only("group_code_img", "enterprice_pic", "regist_copy", "logo");
			$this->moveImages($imgArr, env("OTHERS_DIR"));
			$data["uid"] = $uid;
			EnterpricePowerusersBase::create($data);
			Users::where("id", $uid)->update(["role_id" => env("ENERGY")]);
			$uSession = Users::with(['profile'])->where("id", $uid)->get()[0]->toArray();
			Session::put("user", $uSession);
			return $this->json([]);
		}
		else
		{
			return;
		}
	}

	/**
	 * Show the form for creating a new resource.
	 *
	 * @return Response
	 */
	public function create()
	{
		//
	}

	/**
	 * Store a newly created resource in storage.
	 *
	 * @return Response
	 */
	public function store()
	{
		//
	}

	/**
	 * Display the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function show($id)
	{
		//
	}

	/**
	 * Show the form for editing the specified resource.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function edit($id)
	{
		//
	}

	/**
	 * Update the specified resource in storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function update($id)
	{
		//
	}

	/**
	 * Remove the specified resource from storage.
	 *
	 * @param  int  $id
	 * @return Response
	 */
	public function destroy($id)
	{
		//
	}

}
